package com.wanxi.action;

import com.wanxi.util.Tool;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CallName {
    public static void main(String[] args) throws IOException, InterruptedException {

        String path = "E:\\wanxi\\step-2\\java02-0921\\day21OtherIOStream\\src\\com\\wanxi\\action";
        String fileName = "name.txt";
        Reader reader = new InputStreamReader(Tool.getInputStream(path, fileName));
        BufferedReader inputStreamReader = new BufferedReader(reader);
        String result = null;
        List<String> list = new ArrayList<>();
        while ((result = inputStreamReader.readLine()) != null) {
            list.add(result);
        }
        inputStreamReader.close();

        System.out.println(list);
        int count = 1;
        while (true) {
            Thread.sleep(1000);
            count++;
            if (count == 3) {
                System.out.println(list.get(0));
            } else {
                callName(list);
            }

        }

    }

    private static void callName(List<String> list) {
        Random random = new Random();
        int i = random.nextInt(list.size());
        System.out.println(list.get(i));
    }
}
